	var userId = getQueryString("userId");        //新人工号
	var entity = null;
	//var department = getQueryString("department");         //主管工号
	$(function(){
		function sliceString(obj,num,maxHeight){  //obj为JQ对象，不是DOM对象
			  var textHeight = obj.height();  //获取此时层的高度
			   var cutText = obj.html().slice( 0 , num+2 );
			  while(textHeight > maxHeight){ //如果高度超了，就执行下面脚本
			    cutText = obj.html().slice( 0 , obj.html().length - 6 ) + "..." ;  //去掉最后的6个字符并加上省略号
			    obj.html(cutText);  //重写DOM内容
			    textHeight = obj.height;  //再次获取新的高度，没这句会死循环，如果这时高度没超，循环停止

			  }
		}
		//初始化界面
		initAction();
	
		var nine_Obj = $(".nine_teach ul li p");
		var three_Obj = $(".three_accompany ul li p");
		var new_Obj = $(".new_talk ul li p");

		for(var i = 0; i< nine_Obj.length; i++){
			sliceString($(nine_Obj[i]),100,25);	
		}
		for(var i = 0; i< three_Obj.length; i++){
			sliceString($(three_Obj[i]),100,25);	
		}
		for(var i = 0; i< new_Obj.length; i++){
			sliceString($(new_Obj[i]),100,25);	
		}
		$('ul li img').on('click',function(){
			$('.through_mask').fadeIn('fast',function(){
				$('.detials_content').slideDown('fast');
			})
		});
		$('.finish_see').on('click',function(){
			$('.through_mask').fadeOut('fast',function(){
				$('.detials_content').slideUp('fast');
			})
		})
		
	})
	
	function initAction(){
		//陪访
		pstr = "";
		//九辅
		jstr = "";
		//话术
		hstr = "";
		$.ajax({
			url: API_URL+'person/personRecord?id='+userId,
			type: 'GET',
			dataType: "JSON",
			async: false,
			success: function (obj){
				//签约时间
				$("#contractDate").html(obj.status.msg);
				entity = obj;
				for(var i=0;i<obj.data.length;i++){
					//话术
					if(obj.data[i].type==1){
						if(null != obj.data[i].recordId){
							pstr+="<li><div><em>辅导</em><img src='../img/"+obj.data[i].icon+"' alt=''  onclick='opMsg("+(obj.data[i].censorshipon)+",\""+obj.data[i].recordId+"\");'></div><p>"+obj.data[i].name+"</p></li>";
						}else{
							pstr+="<li><div><img src='../img/"+obj.data[i].icon+"' alt=''  onclick='opMsg("+(obj.data[i].censorshipon)+");'></div><p>"+obj.data[i].name+"</p></li>";
						}
					//九次辅导
					}else if(obj.data[i].type==2){
						if(null != obj.data[i].recordId){
							if(obj.data[i].coach==1&&obj.data[i].customs==1){
								jstr+="<li><div><em>辅导</em><em class='guan'>通关</em><img src='../img/"+obj.data[i].icon+"' alt='' onclick='opMsg("+(obj.data[i].censorshipon)+",\""+obj.data[i].recordId+"\")'></div><p>"+obj.data[i].name+"</p></li>";
							}else if(obj.data[i].coach==1){
								jstr+="<li><div><em>辅导</em><img src='../img/"+obj.data[i].icon+"' alt='' onclick='opMsg("+(obj.data[i].censorshipon)+",\""+obj.data[i].recordId+"\")'></div><p>"+obj.data[i].name+"</p></li>";
							}else if(obj.data[i].customs==1){
								jstr+="<li><div><em class='guan'>通关</em><img src='../img/"+obj.data[i].icon+"' alt='' onclick='opMsg("+(obj.data[i].censorshipon)+",\""+obj.data[i].recordId+"\")'></div><p>"+obj.data[i].name+"</p></li>";
							}
						}else{
							jstr+="<li><div><img src='../img/"+obj.data[i].icon+"' alt='' onclick='opMsg("+(obj.data[i].censorshipon)+")'></div><p>"+obj.data[i].name+"</p></li>";
						}
					//话术
					}else if(obj.data[i].type==3){
						if(null != obj.data[i].recordId){
							hstr+="<li><div><em class='guan'>通关</em><img src='../img/"+obj.data[i].icon+"' alt='' onclick='opMsg("+(obj.data[i].censorshipon)+",\""+obj.data[i].recordId+"\")'></div><p>"+obj.data[i].name+"</p></li>";
						}else{
							hstr+="<li><div><img src='../img/"+obj.data[i].icon+"' alt='' onclick='opMsg("+(obj.data[i].censorshipon)+")'></div><p>"+obj.data[i].name+"</p></li>";
						}
					}
					
				}
				
				$("#peifang").html(pstr);
				$("#jiufu").html(jstr);
				$("#huashu").html(hstr);
				var str = "";
				
				var utype = getQueryString("utype");
				if(utype!='1'){
					$('.new_talk').after('<div class="scanning"></div');
					$(".scanning").html("<input type='button' value='扫一扫' onclick='opConfirm()'/><input type='button' value='验证码'  onclick='opValidate()'>");
					$('#opConfirmbtn').on('click',function(){
						//alert('点击了扫一扫');
						opConfirm();
					})
				}

			},
			error: function(request){
				alert('错误');
			}
		});
	}
	function opMsg(number,carnetId){
		//获取关卡详细信息
		var str="" ;
		$.ajax({
			url: API_URL+'person/personCustoms?id='+number+'&carnetId='+carnetId,
			type: 'GET',
			dataType: "JSON",
			async: false,
			success: function (obj){
				if(obj.data[0].length>0){
					for(var i=0;i<obj.data[0].length;i++){
							str+="<li>"+obj.data[0][i].info+"</li>";
					}
				}
				//时间初始化
				if(null != obj.data[1]){
					var coachDate = new Date(obj.data[1].coachDate).format("yyyy年MM月dd日");
					var customsDate = new Date(obj.data[1].customsDate).format("yyyy年MM月dd日");
					if(number<4){
						var clearance = "<p class='position'>"+entity.data[number-1].name+"</p>";
						var records = "<p><em>新人</em>"+obj.data[2].userId+"</p><p><em>辅导人</em>"+obj.data[2].coachId+"</p><p><em>辅导时间</em>"+coachDate+"</p>";
						$(".part_one").html(clearance);
						$(".part_two").html(records);
					}else if(number>3&&number<13){
						if(obj.data[1].coach==1&&obj.data[1].customs==1){
							var clearance = "<p class='position'>"+entity.data[number-1].name+"</p><p class='teach_biao'>辅导目标：</p><ul>"+str+"</ul>";
							var records = "<p><em>新人</em>"+obj.data[2].userId+"</p><p><em>辅导人</em>"+obj.data[2].coachId+"</p><p><em>辅导时间</em>"+coachDate+"</p><p><em>守关人</em>"+obj.data[2].customs+"</p><p><em>守关时间</em>"+customsDate+"</p>";
							$(".part_one").html(clearance);
							$(".part_two").html(records);
						}else if(obj.data[1].coach==1){
							var clearance = "<p class='position'>"+entity.data[number-1].name+"</p><p class='teach_biao'>辅导目标：</p><ul>"+str+"</ul>";
							var records = "<p><em>新人</em>"+obj.data[2].userId+"</p><p><em>辅导人</em>"+obj.data[2].coachId+"</p><p><em>辅导时间</em>"+coachDate+"</p>";
							$(".part_one").html(clearance);
							$(".part_two").html(records);
						}else if(obj.data[1].customs==1){
							var clearance = "<p class='position'>"+entity.data[number-1].name+"</p><p class='teach_biao'>辅导目标：</p><ul>"+str+"</ul>";
							var records = "<p><em>新人</em>"+obj.data[2].userId+"</p><p><em>守关人</em>"+obj.data[2].customs+"</p><p><em>守关时间</em>"+customsDate+"</p>";
							$(".part_one").html(clearance);
							$(".part_two").html(records);
						}
					}else if(number>12&&number<20){
						var clearance = "<p class='position'>"+entity.data[number-1].name+"</p>";
						var records = "<p><em>新人</em>"+obj.data[2].userId+"</p><p><em>守关人</em>"+obj.data[2].customs+"</p><p><em>守关时间</em>"+customsDate+"</p>";
						$(".part_one").html(clearance);
						$(".part_two").html(records);
					}
				}else {
					var clearance = "<p class='position'>"+entity.data[number-1].name+"</p>";
					if(number>3&&number<13){
						clearance +="<p class='teach_biao'>辅导目标：</p><ul>"+str+"</ul>";
					}
					$(".part_one").html(clearance);
					$(".part_two").html("");
				}
			}
		})
	}

	function getEntity(){
		return entity;
	}

	//var type = 1;   //获取通关或辅导类型 
	//var check_nomber = "1,2";  //有几个辅导或关卡
	function opConfirm(){
		wx.scanQRCode({
			needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
			scanType: ["qrCode"], // 可以指定扫二维码还是一维码，默认二者都有
			success: function (res) {
				var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
				//alert(result);
				//window.location = "teach_confirm.html?userId="+userId+"&"+result;
				var strs = "teach_confirm.html?tmp_time="+(new Date()).valueOf()+"&userId="+userId+"&"+result;
				//alert(strs);
				window.location = strs;
			},
			fail: function (res) {
				alert(JSON.stringify(res));
			}
		});
		//window.location = "teach_confirm.html?type="+type+"&coachid=37974318&check_val="+check_nomber+"&userId="+userId;
	}
	function opValidate(){
		$('.validate').fadeIn('fast');
		$('.validate .cancel_btn').on('click',function(){
			$('.validate').fadeOut('fast');
		});
		$('.validate .sure_btn').on('click',function(){
			var code = $('.code').val();
			if(code==''){
				alert('请输入验证码!');
				return;
			}

			//输入验证码
			$.ajax({
				url: API_URL+'verificationcode/findByCode?vercode='+code,
				type: 'GET',
				dataType: "JSON",
				async: false,
				success: function (obj){
					if(obj.status.code==0){
						var str_prm = "type="+obj.basedata.type+"&coachid="+obj.basedata.coachid+"&check_val="+obj.basedata.check_val;
						var res_url = "teach_confirm.html?tmp_time="+(new Date()).valueOf()+"&userId="+userId+"&"+str_prm;
						window.location = res_url;
					}else if(obj.status.code==-1){
						alert('验证码错误！');
					}else if(obj.status.code==-2){
						alert('验证码已超时，请重新生成！');
					}
				}
			});
			//alert('成功');
		});
	}